﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IPIdee.MapServices.Client.Entities.Coordinates;

namespace IPIdee.MapServices.Client.ServiceLogic.LocationNaming
{
    public class LocationNameService
    {
        static LocationNameService()
        {
            locationNameServiceClient = new IPIdee.MapServices.Client.ServiceLogic.LocationNameServiceReference.LocationNameServiceClient();
        }

        private static IPIdee.MapServices.Client.ServiceLogic.LocationNameServiceReference.LocationNameServiceClient locationNameServiceClient; 

        public LatLngCoordinate ResolveToLatLngCoordinate(string domainName, string name) 
        {    
            var remoteLatLngCoordinate = locationNameServiceClient.ResolveToLatLngCoordinate(domainName, name);
            //
            // convert to local type
            //
            LatLngCoordinate result = new LatLngCoordinate()
            {
                Latitude = remoteLatLngCoordinate.Latitude,
                Longitude = remoteLatLngCoordinate.Longitude,
                Zoom = remoteLatLngCoordinate.Zoom
            };

            return result;
        }

        public void RegisterLocationName(string privateKey, string domainName, string name, LatLngCoordinate latLngCoordinate)
        {
            //
            // convert to remote type
            //
            IPIdee.MapServices.Client.ServiceLogic.LocationNameServiceReference.LatLngCoordinate remoteLatLngCoordinate = new IPIdee.MapServices.Client.ServiceLogic.LocationNameServiceReference.LatLngCoordinate()
            {
                Latitude = latLngCoordinate.Latitude,
                Longitude = latLngCoordinate.Longitude,
                Zoom = latLngCoordinate.Zoom
            };

            locationNameServiceClient.RegisterLocationName(privateKey, domainName, name, remoteLatLngCoordinate);
        }
    }
}
